package com.example.wangzh.developkit.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.wangzh.developkit.R;

import java.util.ArrayList;
import java.util.List;

public class KeybordGridViewAdapter extends BaseAdapter {

	private List<String> key_values;
	private Context context;

	public KeybordGridViewAdapter(Context context){
		this.context = context;
		this.key_values  = getKeyValues();

	}
	
   private List<String> getKeyValues(){
	   List<String> values = new ArrayList<String>();
	   for(int index=0 ; index <12 ;index++){
		  if(index < 9) {
			  values.add(String.valueOf(index+1));
		  }else if(index == 9 || index == 11){
			  values.add("");
		  }else if(index == 10 ){
			  values.add(String.valueOf(0));

		  }
	   }
	   return values;
   }
	public int getCount() {
		return key_values.size();
	}

	
	public Object getItem(int position) {
	
		return null;
	}

	
	public long getItemId(int position) {
		
		return position;
	}

	

	public View getView(int position, View convertView, ViewGroup parent) {
		final ViewHolder holder;

		
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = holder.getView();
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		setTextValus(position,holder);
		
		return convertView;
	}

	private void setTextValus(int position ,ViewHolder holder){
		String value = key_values.get(position);
		holder.tv_value.setText(value);
		if(position == 11){
			holder.tv_value.setBackgroundResource(R.drawable.selector_keybord_gride_iv);
		}
		if(position == 9){
			holder.tv_value.setEnabled(false);
		}

	}
	
	private class ViewHolder{
		
		private TextView tv_value;
		private View convertView;
		private ViewHolder()  {

			convertView = LayoutInflater.from(context).inflate(R.layout.grid_item_keybord_tv, null);
			tv_value = (TextView) convertView.findViewById(R.id.btn_keys);
			convertView.setTag(this);
		}

		private View getView() {
			return convertView;
		}
	}
	
}
